package com.edroid.apkhooker.home;

import com.edroid.apkhooker.db.SettingsSystemDB;

import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.service.SystemServiceGetter;
import com.example.utils.Zmlib;

/**
 * 
 * @author YYichou 2014-6-24
 *
 */
public class FunctionFragment extends ListFragment {
	static String[] FUNC_ITEMS = {
		"重启",
		"测试",
		"静默安装",
		"锁屏 解锁",
		"检测屏幕状态"
	};
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		setListAdapter(new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, 
				FUNC_ITEMS));
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
	    switch (position) {
	        case 0: {
	        	SystemServiceGetter.getPermissionService().reboot();
	            break;
	        }
	        
	        case 1: {
	            break;
	        }
	        
            case 2: {
            	SystemServiceGetter.getPermissionService().install("/sdcard/test.apk");
                break;
            }
            
            case 3: {
            	SystemServiceGetter.getPermissionService().deviceSleep(SystemClock.uptimeMillis());
                getListView().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                    	SystemServiceGetter.getPermissionService().deviceWakeUp(SystemClock.uptimeMillis());
                    }
                }, 3000);
                break;
            }
            
            case 4: {
                getListView().getHandler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
                        Zmlib.toast(getActivity().getApplicationContext(),"isScreenOn? " + pm.isScreenOn());
                        SystemServiceGetter.getPermissionService().deviceWakeUp(SystemClock.uptimeMillis());
                    }
                }, 3000);
                
                break;
            }

            default:
                break;
        }
	}
}
